package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.AdminDao;
import com.pojo.AdminPojo;
import com.util.Log;


public class EditAdminPwd extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		HttpSession session = request.getSession(true);
		
		String password = request.getParameter("password");
		String password1 = request.getParameter("password1");
		String password2 = request.getParameter("password2");
		
		String message;
		if (password.equals("")){
			message = "请输入原密码 ";
		}else if (password2.equals("")){
			message = "请输入确认密码";
		}  else if (password1.equals("")){
			message = "请输入新密码";
		} else if (!password1.equalsIgnoreCase(password2)){
			message = "新密码跟确认密码不一致";
		} else {
			String user = (String) session.getAttribute("curradmin");
			AdminDao dao = new AdminDao();
			message = "密码修改失败!";
			if(dao.updatePwd(user,password,password1)) 
				message = "密码修改成功";
			dao.closeAll();
		}
		String json = "{\"status\":\""+message+"\"}";
		Log.write(json);
		out.println(json);
		out.flush();
        out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
